import axios from 'axios'

const ajax = axios.create({
	// baseURL: 'http://localhost:1337'
	baseURL: 'http://139.155.233.245:1337'
})


ajax.interceptors.request.use((config) => {
	if (window.sessionStorage.getItem("token") && (config.data.needToken !== false)) {
		config.headers.Authorization = `Bearer ${window.sessionStorage.getItem("token")}`
	}
	if (config.data.needToken === false) {
		delete config.data.needToken
	}
	return config
})



export const getToken = () => {
	return ajax.post(`/auth/local`, {
		identifier: 'yangxinqiao',
		password: '1992yxqH',
		needToken: false
	})
}


export const addContact = (data) => {
	return ajax.post(`/contacts`, {
		...data
	})
}
